#include "dialogdisteuclintervale.h"

DialogDistEuclIntervale::DialogDistEuclIntervale(QWidget *parent) :
    QDialog(parent)
{
    ui.setupUi(this);
}

DialogDistEuclIntervale::DialogDistEuclIntervale(QWidget *parent, QList<Image> listeImages, bool couranteEnGris) :
    QDialog(parent)
{
    int i, nbItem=0;

    ui.setupUi(this);

    correspondance = (int *) malloc(listeImages.size()*sizeof(int));

    for(i=0;i<listeImages.size();i++)
    {
        if(listeImages[i].estGris == couranteEnGris)
        {
            ui.comboBoxImage->addItem(QString((listeImages[i].getNom()).c_str()));
            correspondance[nbItem]=i;
            nbItem++;
        }
    }

    connect(ui.buttonBoxOkAnnuler, SIGNAL(accepted()), this, SLOT(validation()));
}

DialogDistEuclIntervale::~DialogDistEuclIntervale()
{

}

void DialogDistEuclIntervale::validation()
{
    int v1,v2;
    v1 = ui.spinBoxIntervale1->value();
    v2 = ui.spinBoxIntervale2->value();
    if(v1>v2)
    {
        emit retourDialog(v2,v1,correspondance[ui.comboBoxImage->currentIndex()]);
    }
    else
    {
        emit retourDialog(v1,v2,correspondance[ui.comboBoxImage->currentIndex()]);
    }
    accept();
}

